# -*- coding: utf-8 -*-

import json
import time
import os
import pdb
import xml.etree.ElementTree as ET
import logging
import uuid
import message_types_res as message_types

# from memory_profiler import profile

class JsonMessageProcessor:
    def __init__(self):
        logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',\
            level=logging.DEBUG)

    def encode_login_req(self, d):
        msg = {}
        msg["msg_type"] = message_types.kLoginReq
        msg["timestamp"] = str(round(time.time() * 1000))
        
        msg["data"] = d
        json_str = json.dumps(msg, ensure_ascii=False).encode("gbk")

        # print(json_str)
        return json_str

    def encode_pic_req(self, d):
        msg = {}
        msg["msg_type"] = message_types.kFrameReq
        msg["timestamp"] = str(round(time.time() * 1000))
        
        msg["data"] = d
        json_str = json.dumps(msg, ensure_ascii=False).encode("gbk")

        # print(json_str)
        return json_str

      

    def encode_heartbeat_req(self, d):
        msg = {}
        msg["msg_type"] = message_types.kHeartReq
        msg["timestamp"] = str(round(time.time() * 1000))
        
        msg["data"] = d
        json_str = json.dumps(msg, ensure_ascii=False).encode("gbk")

        # print(json_str)
        return json_str

    def encode_status_ntf(self, d):
        msg = {}
        msg["msg_type"] = message_types.kStatusNtf
        msg["timestamp"] = str(round(time.time() * 1000))

        msg["data"] = d
        json_str = json.dumps(msg, ensure_ascii=False).encode("gbk")
        # print(json_str)
        return json_str

####################################################################
    
    def decode_login_rsp(self, d):
        obj = json.loads(d)
        code = obj["data"]["code"]
        
        return code 

    def decode_heart_rsp(self, d):
        obj = json.loads(d)
        code = obj["data"]["code"]
        
        return code
    
    def decode_pic_rsp(self, d):        
        return d


if __name__ == "__main__":
    pass
